import React, { Component } from 'react'

export default class TodoFooter extends Component {
    render() {
        const arrLength = this.props.todoList.length
        const checkedNum = this.props.todoList.reduce((prevNum, item)=>{
            if(item.isChecked) prevNum++
            return prevNum
        }, 0)
        let isAllChecked = checkedNum===arrLength
        if(checkedNum === 0 && arrLength === 0) {
            isAllChecked = false
        }

        return (
            <div className="todo-footer">
                <label>
                    <input onChange={()=>this.props.changeCheckedAll(!isAllChecked)} checked={isAllChecked} type="checkbox" />
                </label>
                <span>
                    <span>已选{checkedNum}</span> / 全部{arrLength}
                </span>
                <button onClick={this.props.delAllChecked} className="btn btn-danger">清除已完成任务</button>
            </div>
        )
    }
}
